package com.subsequent.controller;

import com.subsequent.dto.UserDto;
import com.subsequent.service.UsersService;
import com.subsequent.utils.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/login")
public class LoginController {
    @Resource
    private UsersService usersService;

    @PostMapping("/loginDto")
    public Result loginDto(@RequestBody UserDto dto) {
        System.err.println(dto);
        try {
            if(dto.getLoginType().equals("password")){
                return usersService.login(dto);
            }else {
                return usersService.loginCode(dto);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Result.error("服务异常");
    }
    @GetMapping("getCode")
    public Result getCode(){
       return usersService.getCode();
    }
    @PostMapping("UpdatePassword")
    public Result UpdatePassword(@RequestBody UserDto dto){
        try {
            return usersService.UpdatePassword(dto);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Result.error("服务异常");
    }
}
